﻿using System.Web.Mvc;
using ilgolosone.DomainModel.Repositories;
using ilgolosone.Persistence.NH.Data;
using ilgolosone.Persistence.NH.Data.Impl;
using ilgolosone.Persistence.NH.Repositories;
using ilgolosone.Shared.Data;
using Microsoft.Practices.Unity;

namespace ilgolosone.DependencyResolver.Unity
{
    public class DefaultRegistry : IUnityContainerRegistry
    {
        public void Configure(IUnityContainer container)
        {
            container.RegisterType<IControllerFactory, UnityControllerFactory>(
                new ContainerControlledLifetimeManager());

            container.RegisterType<ISessionCreator, NHibernateStandardSessionCreator>(
                new ContainerControlledLifetimeManager());

            container.RegisterType<INHibernateUnitOfWork, NHibernateUnitOfWork>(
                new HybridLifetimeManager());
            container.RegisterType<IUnitOfWork, NHibernateUnitOfWork>(
                new HybridLifetimeManager());

            container.RegisterType(
                typeof(IRepository<>),
                typeof(NHibernateRepository<>)
            );

            container.RegisterType<ISpecialtyRepository, SpecialtyRepository>();
            container.RegisterType<IRestaurantRepository, RestaurantRepository>();
            container.RegisterType<IReservationRepository, ReservationRepository>();
        }
    }
}